package org.weishe.pagerank.hbase;

import java.util.ArrayList;

import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.xuexi.hbase.HBaseDBHelper;

public class PeopleInit {
	// private HBaseAdmin admin;
	// private Configuration conf;
	// private HTable htable;
	HBaseDBHelper dbHelper = HBaseDBHelper.getInstance();
	String tableName = "t_people";

	@Test
	public void createTable() {

		String columnFamilys[] = { "cf1" };

		byte[][] splits = HBaseDBHelper.getHexSplits(1 + "", 10000 + "", 6);
		dbHelper.createTable(tableName, columnFamilys, splits);

	}

	@Test
	public void createPeopleRank() {
		String columnFamilys[] = { "cf1" };
		byte[][] splits = HBaseDBHelper.getHexSplits(1 + "", 10000 + "", 6);
		dbHelper.createTable("t_people_rank", columnFamilys, splits);

	}

	@Test
	public void initDate() {
		/*
		 * A,1,B,C,D //B,1,C,D //C,1,D //D,1,B
		 */
		ArrayList<String> fans1 = new ArrayList<String>();
		fans1.add("B");
		fans1.add("C");
		fans1.add("D");
		PeopleRank p1 = new PeopleRank();
		p1.setWho("A");
		p1.setWight(1);
		p1.setFans(fans1);

		ArrayList<String> fans2 = new ArrayList<String>();
		fans2.add("C");
		fans2.add("D");
		PeopleRank p2 = new PeopleRank();
		p2.setWho("B");
		p2.setWight(1);
		p2.setFans(fans2);

		ArrayList<String> fans3 = new ArrayList<String>();
		fans3.add("D");
		PeopleRank p3 = new PeopleRank();
		p3.setWho("C");
		p3.setWight(1);
		p3.setFans(fans3);

		ArrayList<String> fans4 = new ArrayList<String>();
		fans4.add("B");
		PeopleRank p4 = new PeopleRank();
		p4.setWho("D");
		p4.setWight(1);
		p4.setFans(fans4);

		String s1 = JSON.toJSONString(p1);
		String s2 = JSON.toJSONString(p2);
		String s3 = JSON.toJSONString(p3);
		String s4 = JSON.toJSONString(p4);

		dbHelper.insert(tableName, 1 + "", "cf1", "obj", s1);
		dbHelper.insert(tableName, 2 + "", "cf1", "obj", s2);
		dbHelper.insert(tableName, 3 + "", "cf1", "obj", s3);
		dbHelper.insert(tableName, 4 + "", "cf1", "obj", s4);

	}

	@Test
	public void scan() {
		dbHelper.scaner(tableName);
	}
}
